package net.uhuijia.goods.goodintroduce.service.impl;

import net.uhuijia.constants.DBConst;
import net.uhuijia.enums.GoodIntroduceType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import net.uhuijia.appbase.service.CrudService;
import net.uhuijia.goods.goodintroduce.persistence.dao.GoodIntroduceDao;
import net.uhuijia.goods.goodintroduce.persistence.model.GoodIntroduce;
import net.uhuijia.goods.goodintroduce.persistence.model.GoodIntroduceExample;
import net.uhuijia.goods.goodintroduce.persistence.model.GoodIntroduceExample.Criteria;
import net.uhuijia.goods.goodintroduce.service.GoodIntroduceService;

import java.util.ArrayList;
import java.util.List;


@Service
@Transactional
public class GoodIntroduceServiceImpl
     extends CrudService<GoodIntroduceDao,GoodIntroduce,GoodIntroduceExample>
     implements  GoodIntroduceService {
	
	@Autowired
	private GoodIntroduceService goodIntroduceService;

	@Override
	public GoodIntroduce addGoodIntroduce(String goodId, String image, String type) {
		GoodIntroduce goodIntroduce = new GoodIntroduce();
		this.initDefalutFields(goodIntroduce);
		goodIntroduce.setGoodId(goodId);
		goodIntroduce.setImage(image);
		goodIntroduce.setType(type);
		goodIntroduceService.add(goodIntroduce);
		return goodIntroduce;
	}
	/**
	 * @Author xzj
	 * @Description //根据商品spuId  以及 类型查询 商品简介图片
	 * @Date  2018/10/6
	 * @Param
	 * @return
	 **/
	@Override
	public List<GoodIntroduce> findGoodIntroduceBySpuIdAndType(String spuId, GoodIntroduceType goodIntroduceType) {
		GoodIntroduceExample example = new GoodIntroduceExample();
		Criteria criteria = example.createCriteria();
		criteria.andIsEffectiveEqualTo(DBConst.TRUE);
		criteria.andGoodIdEqualTo(spuId);
		criteria.andTypeEqualTo(goodIntroduceType.getType());
		List<GoodIntroduce> goodIntroduces = this.list(example);
		return goodIntroduces;
	}

	/**
	 * @Author xzj
	 * @Description //根据商品spuId  以及 类型查询 商品简介图片
	 * @Date  2018/10/6
	 * @Param
	 * @return
	 **/
	@Override
	public List<String> findGoodIntroduceImagesBySpuIdAndType(String spuId, GoodIntroduceType goodIntroduceType) {
		List<GoodIntroduce> goodIntroduces = this.findGoodIntroduceBySpuIdAndType(spuId,goodIntroduceType);
		List<String> images = new ArrayList<>();
		for(GoodIntroduce goodIntroduce : goodIntroduces){
			String image = goodIntroduce.getImage();
			images.add(image);
		}
		return images;
	}
}